home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / lightwave / cgplwlist / cgplw00001-00250.txt / 000198_koren@hpfcogv.fc.hp.com_Wed Nov 23 08:21:51 PST 1994.msg < prev    next >
Text File  |  1994-12-25  |  5KB  |  170 lines

  1. Article: 200 of comp.graphics.packages.lightwave
  2. Xref: netcom.com comp.graphics.packages.lightwave:200
  3. Path: netcom.com!ix.netcom.com!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!csn!col.hp.com!fc.hp.com!news.fc.hp.com!koren
  4. From: koren@hpfcogv.fc.hp.com (Steve Koren)
  5. Newsgroups: comp.graphics.packages.lightwave
  6. Subject: gears macro
  7. Date: 23 Nov 1994 15:06:03 GMT
  8. Organization: Hewlett Packard Ft. Collins
  9. Lines: 155
  10. Distribution: world
  11. Message-ID: <KOREN.94Nov23080603@hpfcogv.fc.hp.com>
  12. NNTP-Posting-Host: hpfcogv.fc.hp.com
  13.  
  14.  
  15. It seems from the group charter than small ARexx macros are fair game,
  16. so here is my humble contribution.  It is a modeler macro which makes
  17. gears, such as for bicycle chainrings and whatnot.
  18.  
  19. (Has anyone written a macro to make machine screws?  I'm looking for one
  20. of those so I don't have to write it myself :-) ).
  21.  
  22.   - steve
  23.  
  24. ~~~ cut here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. /* CMD: Gear
  26.  * Make gears of user defined size in Modeler
  27.  * By Steve Koren Copyright ï¿½ 1994 Steve Koren.
  28.  */
  29.  
  30. /* -- See if we have any parameters up front ------------------------------ */
  31.  
  32. arg name teeth rad_inner rad_outer thickness Ax
  33.  
  34. if name="" then name="Gear"
  35. else name=strip(name)
  36.  
  37. if teeth=""     then teeth=20
  38. if rad_inner="" then rad_inner=.4
  39. if rad_outer="" then rad_outer=.5
  40. if thickness="" then thickness=.1
  41. if Ax=""        then Ax='Y'
  42. cen = 0 0 0
  43. flist = Angular Smooth
  44.  
  45. /* -- Load proper function libraries -------------------------------------- */
  46.  
  47. signal on error
  48. signal on syntax
  49.  
  50. call addlib "rexxsupport.library", 0, -30, 0
  51. MATHLIB="rexxmathlib.library"
  52. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  53.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  54.         call notify(1,"!Can't find "MATHLIB)
  55.         exit
  56.         END
  57.  
  58. libadd = addlib("LWModelerARexx.port",0)
  59.  
  60.  
  61. /* -- Generate our requester ---------------------------------------------- */
  62.  
  63. call req_begin "Gear Generator"
  64.  
  65. AxId    = req_addcontrol("Axis", "CH",'X Y Z')
  66. TeethID = req_addcontrol("Teeth",'N')
  67. InnerID = req_addcontrol("Inner Radius",'N',1)
  68. OuterID = req_addcontrol("Outer Radius",'N',1)
  69. ThickID = req_addcontrol("Thickness",'N',1)
  70. TypeID  = req_addcontrol('Type:','CV',FList)
  71. CenID   = req_addcontrol("Center",'V',1)
  72. SurfId  = req_addcontrol("Surface",'R')
  73.  
  74. call req_setval AxId, 3
  75. call req_setval TeethID, 20,20
  76. call req_setval InnerID, 1,1
  77. call req_setval OuterID, 1.1,1.1
  78. call req_setval ThickID, .1,.1
  79. call req_setval CenID,0
  80. call req_setval TypeID,1
  81.  
  82. /* -- Post our requester and ask for input -------------------------------- */
  83.  
  84. if (~req_post()) then do
  85.     call req_end
  86.     exit
  87. end
  88.  
  89. teeth     = req_getval(TeethId)
  90. rad_inner = req_getval(InnerId)
  91. rad_outer = req_getval(OuterId)
  92. thickness = req_getval(ThickId)
  93. Ax        = req_getval(AxId)
  94. name      = req_getval(SurfId)
  95. cen       = req_getval(CenId)
  96. gtype     = req_getval(TypeID)
  97.  
  98. call req_end()
  99.  
  100. t_ang = 360.0 / teeth / 57.2957794
  101.  
  102. /* -- Generate a polygon -------------------------------------------------- */
  103.  
  104. vl=""
  105. cx = word(cen,1)
  106. cy = word(cen,2)
  107. cz = word(cen,3) - thickness/2
  108.  
  109. call ADD_BEGIN()
  110.   call SURFACE("___GEAR")
  111.  
  112.   do tooth=0 to teeth-1
  113.     a1  = t_ang * tooth
  114.     a2  = a1 + (t_ang*3/6)
  115.     a3  = a1 + (t_ang*4/6)
  116.     a4  = a1 + (t_ang*5/6)
  117.  
  118.     vl = vl add_point((rad_inner * sin(a1)+cx) (rad_inner * cos(a1)+cy) cz)
  119.     vl = vl add_point((rad_inner * sin(a2)+cx) (rad_inner * cos(a2)+cy) cz)
  120.     vl = vl add_point((rad_outer * sin(a3)+cx) (rad_outer * cos(a3)+cy) cz)
  121.     vl = vl add_point((rad_outer * sin(a4)+cx) (rad_outer * cos(a4)+cy) cz)
  122.  
  123.   end
  124.  
  125.   if gtype=2 then do
  126.     call ADD_CURVE vl
  127.     end
  128.   else do
  129.     call ADD_POLYGON vl
  130.     end
  131.  
  132. call ADD_END()
  133.  
  134. /* -- Make it part of the right surface ----------------------------------- */
  135.  
  136. call SEL_MODE(USER)
  137. call SEL_POLYGON(CLEAR, NVGT, 1)
  138. call SEL_POLYGON(SET,SURFACE, "___GEAR")
  139.  
  140. if gtype=2 then do
  141.   call FREEZECURVES()
  142. end
  143.  
  144. /* -- Generate proper thinkness ------------------------------------------- */
  145.  
  146. call EXTRUDE(Z, thickness, 1)
  147.  
  148. call CHANGESURFACE(name)
  149.  
  150. /* -- Rotate the new gear into the proper orientation --------------------- */
  151.  
  152. if Ax=1 then do       /* X */
  153.   call ROTATE(90, X, cen)
  154.   end
  155. else if Ax=2 then do  /* Y */
  156.   call ROTATE(90, Y, cen)
  157.   end
  158. else if Ax=3 then do  /* Z */
  159.   end
  160.  
  161.  
  162. exit
  163.  
  164. syntax:
  165. error:
  166.   call end_all
  167.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  168.     exit
  169.  
  170.